﻿using Quartz;
namespace ContinuousJobs.Jobs;

public class FirstJob : IJob, IHasNextJob
{
    public static readonly JobKey Key = JobKey.Create(nameof(FirstJob), "Continuous");

    public IJobDetail NextJob => JobBuilder.Create<SecondJob>().WithIdentity(SecondJob.Key).Build();

    // 如果 Job 里定义了属性，同时 JobDataMap 中有相同的名字，会自动匹配，不需要以下语句获取JobData
    //string greeting = context.JobDetail.JobDataMap.GetString("greeting");
    //string user = context.JobDetail.JobDataMap.GetString("user");
    // jobdetail 和 trigger 都有 jobdata，同名 trigger 覆盖 jobdetail
    // 所以尽量不要用以上语句获取 jobdata，改用以下语句
    //var goodMethod = context.MergedJobDataMap.GetString("a-value");

    public async Task Execute(IJobExecutionContext context)
    {
        Console.WriteLine($"This is first job");
        await Task.Delay(1000);
    }
}
